﻿# -*- coding: utf-8 -*-
from django.db import models
from django.dispatch import dispatcher
from djangotoolbox import fields

class Wave(models.Model):
    title =  models.CharField('Wavelet Title', max_length=512, default='')
    wave_id = models.CharField('Wave ID', max_length=64, unique = True)
    tags = fields.ListField( models.CharField(max_length=500), verbose_name ='Wavelet Tags', blank=True, null= True)

    class Meta:
        verbose_name = 'Wavelet'
        verbose_name_plural = 'Wavelets'
    
    def __unicode__(self):
        return self.title
        
        
class Level(models.Model):
    level = models.IntegerField(verbose_name = "Level", primary_key = True)
    name = models.CharField(verbose_name = 'Level name', max_length=128)
    tags = fields.ListField(models.CharField(max_length=500), verbose_name = "Level Tags")
    
    class Meta:
        verbose_name = 'Level'
        verbose_name_plural = 'Levels'
        
    def __unicode__(self):
        return self.name
        
    def utf_tags(self):
        s = u''
        for tag in self.tags:
            s += tag + u', '
        s = s[:-2]
        return s

    utf_tags.short_description = "Tags"

class Category(models.Model):
    tags = fields.ListField(models.CharField(max_length = 500), verbose_name = "Category tags", blank = True, null = True)
    wave_id = models.CharField('Category Wave ID', max_length=64, unique = True)
    header = models.CharField('Category header', max_length = '500') #, blank = True, null = True)
        
    def utf_tags(self):
        s = u''
        try:
          for tag in self.tags:
              s += tag + u', '
          s = s[:-2]
        except:
          pass
        return s
    utf_tags.short_description = "Tags"
    
    class Meta:
        verbose_name = 'Category'
        verbose_name_plural = 'Categories'
        
        
class ExtendedTag(models.Model):
    name = models.CharField(verbose_name = 'Tag name', max_length=128)
    tags = fields.ListField(models.CharField(max_length=500), verbose_name = "Adding Tags")
    
    class Meta:
        verbose_name = 'Extended tag'
        verbose_name_plural = 'Extended tags'
        
    def __unicode__(self):
        return self.name
        
    def utf_tags(self):
        s = u''
        for tag in self.tags:
            s += tag + u', '
        s = s[:-2]
        return s

    utf_tags.short_description = "Tags"        